import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'

// 主要tabbar
export const layoutRoutes: Array<RouteRecordRaw> = [
	{
		path: '/',
		name: 'home',
		meta: {
			title: 'home',
			keepAlive: true,
		},
		component: () => import('@/views/home/index.vue'),
	},
	{
		path: '/mycenter',
		name: 'mycenter',
		meta: {
			title: 'mycenter',
		},
		component: () => import('@/views/mycenter/index.vue'),
	},
	{
		path: '/shopcart',
		name: 'shopcart',
		meta: {
			title: 'shopcart',
		},
		component: () => import('@/views/shopcart/index.vue'),
	}
]

export const routes: Array<RouteRecordRaw> = [
	{
		path: '/',
		component: () => import('@/layout/index.vue'),
		redirect: '/index',
		// 需要layout的页面
		children: layoutRoutes,
	},

	{
		path: '/login',
		name: 'login',
		component: () => import('@/views/login/index.vue'),
	},
	{
		path: '/account',
		name: 'account',
		component: () => import('@/views/account.vue'),
	},{
		path: '/agreement',
		name: 'agreement',
		component: () => import('@/views/agreement/index.vue'),
	},
	{
		path: '/product',
		name: 'product',
		component: () => import('@/views/agreement/product.vue'),
	},
	{
		path: '/popularizetasks',
		name: 'popularizetasks',
		meta: {
			title: '推广任务量',
		},
		component: () => import('@/views/agreement/popularizetasks.vue'),
	},
	{
		path: '/expandtasks',
		name: 'expandtasks',
		meta: {
			title: '开发任务量',
		},
		component: () => import('@/views/agreement/expandtasks.vue'),
	},
	{
		path: '/activitytasks',
		name: 'activitytasks',
		meta: {
			title: '活动任务量',
		},
		component: () => import('@/views/agreement/activitytasks.vue'),
	},
	{
		path: '/businessperson',
		name: 'businessperson',
		meta: {
			title: '配送商业&联系人',
		},
		component: () => import('@/views/agreement/businessperson.vue'),
	},
	{
		path: '/preview',
		name: 'preview',
		meta: {
			title: '活动任务量',
		},
		component: () => import('@/views/agreement/preview.vue'),
	},
	{
		path: '/demo',
		name: 'demo',
		meta: {
			title: 'demo',
		},
		component: () => import('@/views/agreement/login.vue'),
	},
	// 替代vue2中的'*'通配符路径
	{ path: '/:pathMatch(.*)*', redirect: '/' },
]

const router = createRouter({
	scrollBehavior: () => ({ left: 0, top: 0 }),
	history: createWebHashHistory(),
	routes,
})

router.beforeEach((_to, _from, next) => {
	next()
})

export default router
